<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_FIELDS_PATH."field_text".DIRECTORY_SEPARATOR."field_text.php");
    
	//
    // t_field_datetime
    //
	class t_field_datetime extends t_field_text
	{
        
        // property declaration
		// protected
      

        // property declaration
		// public
		//  D
		public $date_tag = null;
		// G
		const language_position_per_can_not_be_empty = 1;
        const language_position_per_invalid_value = 2;
		const language_position_last = 3;
		
		// P
        //const proper_properties_position_last = 3;
        // method declaration
    	// protected
		//  T
		public $time_tag = null;

		// A
        protected function adds_check_value_method()
        {
            global $g_javascript_namespace;
         	$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"check_value","a_name","
	var local_name = a_name;
	if (a_name == undefined)
		local_name = this.name;
	var local_time_return = true;
	var local_msg = '';    
	var local_time_msg = ''; 
	var local_msg_date_tag = this.html_tag(local_name+'_date_msg');
	var local_msg_time_tag = this.html_tag(local_name+'_time_msg');
    var local_value = this.html_tag(local_name).value.trim();
	var local_time_value = this.html_tag(local_name+'_time').value.trim();
	var local_return = ((local_value != '') || (local_time_value != '') || (!this.can_not_be_empty));
    if (!local_return)
    {
		local_msg = this.can_not_be_empty_msg;
    }
	else 
	{
		if (local_value != '')
		{
			local_return = local_value.validate_date(local_value);
			if (! local_return)
			{
				local_msg = this.invalid_value_msg;
			}    
		}
		
		if (local_time_value != '')
		{
			local_time_return = local_time_value.validate_time(local_time_value);
			if (! local_time_return)
			{
				local_time_msg = this.invalid_value_msg;
			}    
		}
		
	}   
    set_tag_property(['innerHTML'],[local_msg],local_msg_date_tag,true);    
	set_tag_property(['innerHTML'],[local_time_msg],local_msg_time_tag,true);    
	if (!local_return)
    {
		set_tag_style_property(['display'],[''],local_msg_date_tag,true);
    } 
    else
    {
       set_tag_style_property(['display'],['none'],local_msg_date_tag,true);
    }
	if (!local_time_return)
    {
		set_tag_style_property(['display'],[''],local_msg_time_tag,true);
    }   
    else
    {
       set_tag_style_property(['display'],['none'],local_msg_time_tag,true);
    }
    
	return (local_return && local_time_return);
    "); 
	$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
			get_class($this),"edit_row_activation","a_tag_value_name,a_tag_value_edit_name,a_active,a_copy_value","
	var local_value_style = '';
	var local_edit_value_style = 'none';
	if (a_active == true)
	{
		local_value_style = 'none';
		local_edit_value_style = '';
	}
	var local_value = set_tag_style_property(['display'],[local_value_style],a_tag_value_name,true);
	var local_edit_value = set_tag_style_property(['display'],[local_edit_value_style],a_tag_value_edit_name,true);
	var local_edit_time_value = set_tag_style_property(['display'],[local_edit_value_style],a_tag_value_edit_name+'_time',true);
	
	if (a_copy_value)
	{
		if (a_active == true)
		{
			var local_array_value=local_value.innerHTML.split(' '); 
			local_edit_value.value = '';
			local_edit_time_value.value = '';
			for(var i = 0; i<local_array_value.length; i++) 
				if (i == 0)
					local_edit_value.value += local_array_value[i];
				else
					local_edit_time_value.value += local_array_value[i]+' ';
		} 	
		else
		{
			
			local_value.innerHTML = local_edit_value.value.trim()+' '+local_edit_time_value.value.trim();
		} 

	}		
	");
   	$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
		get_class($this),"get_prepared_value","a_name","
	var local_name = a_name;
	if (a_name == undefined)
		local_name = this.name;
	var local_msg_date_tag = this.html_tag(local_name);
	var local_msg_time_tag = this.html_tag(local_name+'_time');        
    return local_msg_date_tag.value + ' ' + local_msg_time_tag.value;
    ");
    
        }
        // G
		protected function get_field_event_script($a_event_type,$a_argouments)
        {			
			$local_return = '';
			return $local_return;
		}
static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = 'TRUE';
				break;                
			}*/
			return $local_return;
		}
		protected function get_proper_properties_position_last()      
		{
            return self::proper_properties_position_last;
        }
		
        // method declaration
    	// public
        public function __construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str)
		{
            parent::__construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str);
            
			
		}

		// C
		
        public function create_tags_structure()
        {
            global $g_javascript_namespace;
            //echo __METHOD__."<BR>";
            //echo "this->proper_properties_array[self::proper_properties_position_per_NULL]: '".$this->proper_properties_array[self::proper_properties_position_per_NULL]."'<br>";
            if (($this->proper_properties_array[self::proper_properties_position_per_NULL] == 1) ||
                (strtoupper($this->proper_properties_array[self::proper_properties_position_per_NULL]) == "TRUE"))
                $local_can_not_be_empty = "true";
            else
                $local_can_not_be_empty = "false";
           // echo "local_can_not_be_empty: $local_can_not_be_empty<br>";
			$local_can_not_be_empty_msg = addslashes($this->lang[self::language_position_per_can_not_be_empty]);	
            $local_invalid_value_msg = addslashes($this->lang[self::language_position_per_invalid_value]);	
            parent::create_tags_structure(
				// ARGUMENTS DECLARATIONS
                "a_can_not_be_empty,a_can_not_be_empty_msg,a_invalid_value_msg",
                // ARGUMENTS VALUES
                "$local_can_not_be_empty,'$local_can_not_be_empty_msg','$local_invalid_value_msg'");
			// proprierties

			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'can_not_be_empty',"a_can_not_be_empty",false);
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'can_not_be_empty_msg',"a_can_not_be_empty_msg",false);	
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'invalid_value_msg',"a_invalid_value_msg",false);                
            // STYLE
			// tags    
            $local_name = $this->common_properties_array[t_base_field::common_properties_position_per_field_name];
            $local_label = $this->proper_properties_array[self::proper_properties_position_per_label];
            if (trim($local_label) != '')
            {
                $local_current_tag = parent::add_tag(t_base_tag_type::btt_label,$local_name . "_label");
                $this->label_tag = $local_current_tag;
				$local_current_tag->set_text_to_include($local_label);
            }    
            // DATE TAG
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_input,
                $local_name);
			$this->date_tag = $local_current_tag;
			$this->main_tag = $local_current_tag;			
            $this->default_start_tag = $this->main_tag;
            $this->default_result_tag = $this->main_tag;
			// message date tag
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_label,$local_name . "_date_msg");
            $this->message_date_tag = $local_current_tag;
			$this->message_date_tag->class_name = t_base_field::error_msg_class_name;	

            // TIME TAG
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_input,
                $local_name."_time");
			$this->time_tag = $local_current_tag;
			
			// message time tag
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_label,$local_name . "_time_msg");
            $this->message_time_tag = $local_current_tag;
			$this->message_time_tag->class_name = t_base_field::error_msg_class_name;	
            // method
            $this->adds_check_value_method();
    
        }
        // G
		public function get_included_in_html_structure($a_name,$a_display,$a_key_tag_name)
		{
			//parent::get_included_in_html_structure($a_name);
			if ($a_display)
			{
				$this->date_tag->add_style_property('display','');
				$this->time_tag->add_style_property('display','');
				$this->message_date_tag->add_style_property('display','');
				$this->message_time_tag->add_style_property('display','');
			}
			else
			{
				$this->date_tag->add_style_property('display','none');
				$this->time_tag->add_style_property('display','none');
				$this->message_date_tag->add_style_property('display','none');
				$this->message_time_tag->add_style_property('display','none');
			}	
			$this->key_tags_list[$a_name] = $a_key_tag_name;
			//echo "a_name: $a_name - a_key_tag_name: $a_key_tag_name<br>";
			$local_label_script = '';
			if (isset($this->label_tag))
				$local_label_script = $this->label_tag->generate_html_code_with_new_name($a_name.t_field_text::postfix_label_tag_name);
			return $local_label_script .
				($this->date_tag->generate_html_code_with_new_name($a_name) .
				$this->message_date_tag->generate_html_code_with_new_name($a_name."_date".t_field_text::postfix_message_tag_name)).
				($this->time_tag->generate_html_code_with_new_name($a_name."_time") .
				$this->message_time_tag->generate_html_code_with_new_name($a_name."_time".t_field_text::postfix_message_tag_name));
		}
		
		public function get_included_in_html_structure_no_edit_mode($a_id,$a_value,$a_label_value)
		{
			
			/*global $g_ambient_namespace;
			echo $a_value;
			$local_date = '';
			$local_time = '';		
			if (trim($a_value) != '')
			{
				$local_datetime_arr = preg_split('/[\s]+/', trim($a_value), -1, PREG_SPLIT_NO_EMPTY); 
				$local_date = date($g_ambient_namespace->php_date_format, strtotime($local_datetime_arr[0]));
				$local_time = time($g_ambient_namespace->php_time_format, strtotime($local_datetime_arr[1]));
				
			}
			return "<label id=\"". $a_id ."\">".trim($local_date. ' ' . $local_time)."</label>";;*/
			
			global $g_ambient_namespace;
			/*if (trim($a_value) != '')
				$a_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_date_value(trim($a_value));;*/
			return "<label id=\"". $a_id ."\">".$a_value."</label>";;
			
			
		}
		
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		public function get_result_action_script($a_event_type,$parent_event_type,
            $a_parameter,$a_content_loader_result)
		{
            return '';
        }		
		
// I
		public function initialize_field_event($a_event_type)
        {			
			
		}
        
       

		

    }
?>    